home *** CD-ROM | disk | FTP | other *** search
- #include <Palettes.h>
-
- #include "GameShellMonitor.h"
- #include "assert_mac.h"
-
- enum {
- /* Who's gonna have 10 monitors connect at once? This
- should be a safe limit. */
- kMaxMonitorsChecked = 10
- };
-
- /*
- Note: This routine is slightly buggy. I haven't had time to fix
- this yet... It works OK for single-monitor systems, and is
- slightly off with multiple-monitor systems.
- */
- short GameShellChooseMonitor(
- GDHandle *monitor,
- unsigned short preferredDepth,
- unsigned short minDepth,
- unsigned short minWidth,
- unsigned short minHeight)
- /*
- This routine, given the parameters, will select the "best fit"
- monitor available. First it will look for the monitor that
- matches the minimum dimensions. It then looks for the those
- with the preferred depth first, and if none are available,
- select those with the minimum available depth.
-
- The routine makes 2 passes. The first pass will query the
- *current* depth of all monitors. If none are found (either
- preferred or minimum) the second pass will query the
- monitors if they're *able* to support the preferred and
- minimum depths. If so, the routine will change the depth.
-
- If a monitor is found, the original depth of the monitor
- will be returned. You can check this value against the
- monitor's current depth to see if the routine was forced
- to change the depth of the monitor.
-
- If no monitors are found, monitor will be set to NULL and
- the routine will return 0.
- */
- {
- Rect monitorRect;
- GDHandle monitorList[kMaxMonitorsChecked];
- GDHandle curMonitor;
- short numMonitors;
- short origDepth;
- long i;
-
- // First make a list of all monitors that fit minimum dim
- numMonitors = 0;
- curMonitor = GetDeviceList();
-
- while (curMonitor != NULL) {
- monitorRect = (**curMonitor).gdRect;
-
- if ( ((monitorRect.right - monitorRect.left) >= minWidth)
- && ((monitorRect.bottom - monitorRect.top) >= minHeight) ) {
- monitorList[numMonitors++] = curMonitor;
- }
-
- curMonitor = GetNextDevice(curMonitor);
- }
-
- // Found no monitors with the requested dimensions
- if (numMonitors == 0) {
- *monitor = NULL;
- return(0);
- }
-
- // Look for any with the preferred depth
- for (i = 0; i < numMonitors; i++) {
- // Get current depth
- origDepth = (**(**monitorList[i]).gdPMap).pixelSize;
-
- if (origDepth >= preferredDepth) {
- if (origDepth != preferredDepth)
- SetDepth(monitorList[i], preferredDepth, 1 << gdDevType, 1);
- *monitor = monitorList[i];
- return(origDepth);
- }
- }
-
- // If we get to here, means didn't find the preferred.
- // Now look for minimum
- for (i = 0; i < numMonitors; i++) {
- origDepth = (**(**monitorList[i]).gdPMap).pixelSize;
-
- if (origDepth >= minDepth) {
- if (origDepth != minDepth)
- SetDepth(monitorList[i], minDepth, 1 << gdDevType, 1);
- *monitor = monitorList[i];
- return(origDepth);
- }
- }
-
- // Are any monitors available that can be at least
- // *set* to the preferred depth?
- for (i = 0; i < numMonitors; i++) {
- origDepth = (**(**monitorList[i]).gdPMap).pixelSize;
-
- if (HasDepth(monitorList[i], preferredDepth, 1 << gdDevType, 1)) {
- SetDepth(monitorList[i], preferredDepth, 1 << gdDevType, 1);
- *monitor = monitorList[i];
- return(origDepth);
- }
- }
-
- // Are any monitors that can be set to the minimum depth?
- for (i =0; i < numMonitors; i++) {
- origDepth = (**(**monitorList[i]).gdPMap).pixelSize;
-
- if (HasDepth(monitorList[i], minDepth, 1 << gdDevType, 1)) {
- SetDepth(monitorList[i], minDepth, 1 << gdDevType, 1);
- *monitor = monitorList[i];
- return(origDepth);
- }
- }
-
- *monitor = NULL;
- return(0);
- } // END GameShellSelectMonitor
-
-
- short GameShellUserSelectMonitor(
- GDHandle *monitor,
- unsigned short preferredDepth,
- unsigned short minDepth,
- unsigned short minWidth,
- unsigned short minHeight)
- {
- // Sorry, not currently implemented.
- return(0);
- } // END GameShellUserSelectMonitor